﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.IO;

namespace XCBPM.Mobile.BLL
{
    public class FormMethod
    {      
        public static string DataTableToJson(DataTable dt)
        {
            if (dt.Rows.Count == 0 || dt == null)
                return "";
            System.Text.StringBuilder sb = new System.Text.StringBuilder("[");
            foreach (DataRow row in dt.Rows)
            {
                sb.Append("[");
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    sb.Append('"' + row[i].ToString() + "\",");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("],");
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append("]");
            return sb.ToString();
        }

        public static string ReadFile(string path)
        {          
            FileInfo fi = new FileInfo(path);
            string FileContent = "";
            if (fi.Exists)
            {
                StreamReader sr = new StreamReader(path, System.Text.Encoding.Default);
                FileContent = sr.ReadToEnd();
                sr.Close();
            }
            return FileContent;
        }
    }
}